

#include "main.h"





Bsw_FTM_Cfg FTM0_Cfg =
{
	.ftmBase 			= 	FTM0,
	.clockName			= 	FTM0_CLK,
	.u32_clockSource	=	1,
	.Clock_Source 		= 	FTM_CLOCK_SOURCE_EXTERNALCLK,
	.Clk_Ps				=	FTM_CLOCK_DIVID_BY_64,
	.u16_Per_value		= 	1249,
	.b_WriteProtection	=	false,
	.b_TimerOverflow	=	false,
	.b_Cpwms			=	false,
};


Bsw_Ftm_Ch_Cfg FTM0_Ch0_Cfg =
{
	.ftmBase			= 	FTM0,
	.u32_ChNum 			= 	0,
	.b_DualChnSync 		= 	false,
	.b_ChnPolarity 		= 	false,
	.u8_ChnEdgelevel 	= 	2,
	.u8_ChnMSnBA 		= 	2,
	.u16_ChnCountVal	= 	9,
};



/********************************************************
**函数名：		ECU_PWM_INIT
**功能：		配置BMS的PWM模块
**输入参数：	无
**返回值：		无
**注意：		根据原理图配置指定的PWM模块
*********************************************************/
void ECU_PWM_INIT(void)
{
	/*FAN_IO*/
	BSW_GPIO_MUX_CONFIG(Bsw_Port_D,PIN15_IDX,PORT_MUX_ALT2);
	BSW_FTM_INIT_PWM(FTM0_Cfg);
	BSW_FTM_CH_INIT(FTM0_Ch0_Cfg);
	/*FAN_FAULT*/
	BSW_GPIO_MUX_CONFIG(Bsw_Port_E,PIN8_IDX,PORT_MUX_AS_GPIO);
	BSW_GPIO_Direction(PTE,PIN8_IDX,0);
	/*FAN_DRV_FLT*/
	BSW_GPIO_MUX_CONFIG(Bsw_Port_E,PIN9_IDX,PORT_MUX_AS_GPIO);
	BSW_GPIO_IRQ_CONFIG(Bsw_Port_E,PIN9_IDX,PORT_INT_RISING_EDGE);
	BSW_GPIO_Direction(PTE,PIN9_IDX,0);
	INT_SYS_EnableIRQ(PORTE_IRQn);
}

/********************************************************
**函数名：		ECU_PWM_Update
**功能：		配置PWM输出的占空比
**输入参数：	无
**返回值：		无
**注意：		配置PWM模块占空比
*********************************************************/
void ECU_PWM_Update(u16 u16_Duty_Val)
{
	u32 u32_Duty = 0;
	u32_Duty = u16_Duty_Val;
	u32_Duty = u32_Duty * 25/2;


	BSW_FTM_Update_PWM(FTM0_Ch0_Cfg,u32_Duty);
}

u8 	FAN_DRVFAULT_Flg = 0;
u8	FAN_DRVFAULT_Count = 0;
u8 ECU_FAN_DRVFAULT_CHECK(void)
{
	u8 u8_Status = 0;
	if(FAN_DRVFAULT_Flg)
	{
		FAN_DRVFAULT_Count = 0;
		FAN_DRVFAULT_Flg = 0;
	}
	else
	{
		if(FAN_DRVFAULT_Count < 200)
		{
			FAN_DRVFAULT_Count++;
		}
		else
		{
			u8_Status = 1;
		}
	}
	return u8_Status;
}


inline void PTE_IO_IRQ(void)
{
	PINS_DRV_ClearPinIntFlagCmd(PORTE,PIN9_IDX);
	FAN_DRVFAULT_Flg = 1;
}






























